<template>
  <div class="outer-container">
    <header>
      <button class="back-button" @click="$router.back()">&lt;</button>
      <h1>通知设置</h1>
  
      <button class="more-button">···</button>
    </header>
    <div class="container">
      <div class="settings-container">
        <div class="settings">
          <div class="setting" v-for="(item, index) in settings" :key="index">
            <span class="left-aligned">{{ item.label }}</span>
            <div :class="['toggle', { active: item.active }]" @click="toggleSetting(index)"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      settings: [
        { label: '账户动账消息微信通知', active: false },
      ],
    };
  },
  methods: {
    toggleSetting(index) {
      try {
        this.settings[index].active = !this.settings[index].active;
      } catch (error) {
        console.error("切换设置时发生错误:", error);
      }
    },
  },
};
</script>

<style scoped>
.left-aligned {
  margin-top: -20px;
  text-align: left;
  font-size: 19px;
  font-family: 'microsoft yahei';
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

h1 {
  padding: 0 20px;
  font-size: 20px;
  color: #444;
}

.back-button {
  position: absolute;
  left: 15px;
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
}

.more-button {
  position: absolute;
  right: 0;
  font-size: 24px;
  background: none;
  border: none;
  cursor: pointer;
}

.outer-container {
  padding: 20px;
  margin: auto;
  display: flex;
  flex-direction: column;
  border: none;
  box-shadow: none;
  background-image: url('../page6/assets_page6/bg1.svg');
  background-size: cover; /* 使背景图片覆盖整个容器 */
  background-position: center; /* 使背景图片居中 */
  background-repeat: no-repeat; /* 防止背景图片重复 */
  min-height: 100vh; /* 确保背景图片覆盖整个视口高度 */
}


.container {
  margin-top: -5px;
  flex-grow: 1;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.settings-container {
  border-radius: 10px;
  padding: 20px;
}

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 15px 0;
}

.toggle {
  margin-top: -9px;
  width: 50px;
  height: 25px;
  background: #ccc;
  border-radius: 50px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle:before {
  content: "";
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  transition: transform 0.3s;
}

.active {
  background: #66bb6a;
}

.active:before {
  transform: translateX(25px);
}
</style>
